"use strict";
/**
 * 游戏流程整合
 */
document.body.onload = function()
{
    var gameBox = document.getElementById("game-box");
    window.start = function() {
        window.vCount = 0;
        window.interV = [];
        gameBox.innerText = null;
        // 加载 game-box 窗体
        var box = makeGameBox();
        var role = addRole("/lost-fly/image-pack/game/plane.png");
        var ctrlerObj = makeCtrler(role);
        box.appendChild(role);  // 加载飞机
        box.appendChild(ctrlerObj.ring);  // 加载控制器
        window.wallFac = setInterval(function() {
            let randLeft = Math.round(Math.random() * (document.body.clientWidth-document.body.clientWidth/10))
            let wall = makeWall(randLeft);
            wallMove(box, wall, randLeft);
        }, 2000);
    };

    // 点击按钮开始
    let st = document.getElementsByClassName("nav-start");
    st[0].addEventListener("click", function(event) {
        clearInterval(window.wallFac);
        for (var i = 0; i < window.interV.length; i++) {
            clearInterval(window.interV[i]);
        }
        var walls = document.getElementsByClassName("wall");
        for (var i = 0; i < walls.length; i++) {
            try {
                walls[i].parentNode.removeChild(walls[i]);
            } catch(e) {
                console.log(e);
            }
        }
        window.start();
    });

    let gb = document.getElementsByClassName("nav-prev");
    gb[0].addEventListener("click", function(event) {
        history.back();
    });
    initGame(gameBox, window.start);
}